import type { Recordable } from '@vben/types';

import { requestClient } from '#/api/request';

export namespace SystemRoleApi {
  export interface SystemRole {
    [key: string]: any;
    id: string;
    name: string;
    permissions: [];
    profile: {
      create_time: string;
      permissions: [];
      remark?: string;
      status: 0 | 1;
    };
  }
}

/**
 * 获取角色列表数据
 */
const getRoleList = (params: Recordable<any>): Promise<Array<SystemRoleApi.SystemRole>> => {
  return requestClient.get('/system/role/', { params });
};

/**
 * 创建角色
 * @param data 角色数据
 */
const createRole = (data: Omit<SystemRoleApi.SystemRole, 'id'>): Promise<SystemRoleApi.SystemRole> => {
  return requestClient.post('/system/role/', data);
};

/**
 * 更新角色
 *
 * @param id 角色 ID
 * @param data 角色数据
 */
const updateRole = (
  id: string,
  data: Omit<SystemRoleApi.SystemRole, 'id'>,
): Promise<SystemRoleApi.SystemRole> => {
  return requestClient.put(`/system/role/${id}/`, data);
};
/**
 * 更新角色
 *
 * @param id 角色 ID
 * @param data 角色数据
 */
const patchRole = (
  id: string,
  data: Omit<SystemRoleApi.SystemRole, 'id'>,
): Promise<SystemRoleApi.SystemRole> => {
  return requestClient.patch(`/system/role/${id}/`, data);
};

/**
 * 删除角色
 * @param id 角色 ID
 */
const deleteRole = (id: string): Promise<any> => {
  return requestClient.delete(`/system/role/${id}/`);
};

export { createRole, deleteRole, getRoleList, patchRole, updateRole };
